package com.pointstar.dp.modules.project.controller;

import java.util.Map;

import com.pointstar.dp.modules.project.entity.ro.SaveInBoundRo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pointstar.dp.common.annotation.SysLog;
import com.pointstar.dp.modules.sys.controller.AbstractController;
import com.pointstar.dp.common.entity.Page;
import com.pointstar.dp.common.entity.R;
import com.pointstar.dp.modules.project.entity.InBoundEntity;
import com.pointstar.dp.modules.project.service.InBoundService;

/**
 * 入库主表
 *
 * @author Korey<m13057531285 @ 1 6 3 . com>
 */
@RestController
@RequestMapping("/inbound")
public class InBoundController extends AbstractController {

    private final InBoundService inBoundService;

    @Autowired
    public InBoundController(InBoundService inBoundService) {
        this.inBoundService = inBoundService;
    }

    /**
     * 查询入库主表列表
     *
     * @param params 查询参数
     * @return 入库主表列表
     */
    @PostMapping("/list")
    public Page<InBoundEntity> list(@RequestBody Map<String, Object> params) {
        return inBoundService.listInBound(params);
    }

    /**
     * 新增
     *
     * @param inBound 入库主表实体类
     * @return 结果
     */
    @SysLog("新增入库主表")
    @PostMapping("/save")
    public R save(@RequestBody InBoundEntity inBound) {
        return inBoundService.saveInBound(inBound);
    }

    /**
     * 商品入库
     *
     * @param saveInBoundRo
     * @return 结果
     */
    @SysLog("新增入库主表及明细表")
    @PostMapping("/saveInBoundAndDetails")
    public R saveInBoundAndDetails(@RequestBody SaveInBoundRo saveInBoundRo) {
        return inBoundService.saveInBoundAndDetails(saveInBoundRo);
    }

    /**
     * 根据id查询详情
     *
     * @param id
     * @return
     */
    @PostMapping("/info")
    public R getById(@RequestBody Long id) {
        return inBoundService.getInBoundById(id);
    }

    /**
     * 修改
     *
     * @param inBound
     * @return
     */
    @SysLog("修改入库主表")
    @PostMapping("/update")
    public R update(@RequestBody InBoundEntity inBound) {
        return inBoundService.updateInBound(inBound);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @SysLog("删除入库主表")
    @PostMapping("/remove")
    public R batchRemove(@RequestBody Long[] id) {
        //return inBoundService.batchRemove(id);
        //更新删除标志和插入负记录
          return inBoundService.batchRemoveLogic(id);

    }

}
